const cookie = {
    /**

     * @description 保存cookie

     * @param {Object} json 需要存储cookie的对象

     * @param {Number} days 默认存储多少天

     */

    setCookie(key, jsonStr, days) {
        // 设置过期时间
        let data = new Date(
            new Date().getTime() + days * 24 * 60 * 60 * 1000
        ).toUTCString();
        document.cookie = key + "=" + jsonStr + "; expires=" + data;
    },

    /**

     * @description 获取cookie

     * @param {String} name 需要获取cookie的key

     */

    getCookie(name) {
        let arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) {
            return unescape(arr[2]);
        } else {
            return null;
        }
    },

    /**

     * @description 删除cookie

     * @param {String} name 需要删除cookie的key

     */

    clearCookie(name) {
        this.setCookie(name,"", -1)
    }

}


export default cookie